package com.motong.gongdan.service;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.motong.gongdan.entity.ProcessSop;
import com.motong.gongdan.mapper.ProcessSopMapper;
import com.motong.gongdan.vo.system.processSop.ProcessSopZoneVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Objects;

/**
 * @author:fff
 * @time:2022/6/9
 */
@Service
public class ProcessSopService extends ServiceImpl<ProcessSopMapper, ProcessSop> {


    public ProcessSop sopCollectionTemplate(String processCode) {
        ProcessSop sopData = this.getOne(new LambdaQueryWrapper<ProcessSop>().eq(ProcessSop::getProcessCode, processCode).eq(ProcessSop::getState, 0));
        if (Objects.nonNull(sopData)) {
            if (StringUtils.hasLength(sopData.getZoneDetail())) {
                sopData.setVos(JSONUtil.toList(sopData.getZoneDetail(), ProcessSopZoneVo.class));
            }
        }
        return sopData;
    }
}
